﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using InstantNaukriDAL;

public partial class Employer_Master : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                clsEmployerDAL objclsEmployeDAL = new clsEmployerDAL();
                FillEmployer();
                //FillddlState();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
    protected void btnsaveEmployeinfo_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["EmployeId"] == null)
            {
                clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
                //Saving User
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                objIN_TB_USER.EMAIL = txtemail.Text;

                if (rbtnLoginId.SelectedValue == "1")
                {
                    objIN_TB_USER.LOGIN_ID = txtemail.Text;
                    objIN_TB_USER.PASSWORD = txtPassword.Text;
                }
                if (rbtnLoginId.SelectedValue == "2")
                {
                    objIN_TB_USER.LOGIN_ID = txtmobile.Text;
                    objIN_TB_USER.PASSWORD = txtPassword.Text;
                }
                objIN_TB_USER.NAME = txtEmployeName.Text;
                objIN_TB_USER.MOBILE = txtmobile.Text;
                objIN_TB_USER.EMAIL = txtemail.Text;
                objIN_TB_USER.STATUS = 1;
                objIN_TB_USER.ROLEID = 3;
                objIN_TB_USER.DOB = Convert.ToDateTime(txtDob.Text);
                objIN_TB_USER.CREATED_BY = 1;
                int UserId = objclsUserLoginDAL.SaveUser(objIN_TB_USER);




                clsEmployerDAL objclsEmployerDAL = new clsEmployerDAL();
                IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
                objIN_TB_EMPLOYER_MST.USER_ID = UserId;
                objIN_TB_EMPLOYER_MST.EMPLOYER_NAME = txtEmployeName.Text;
                objIN_TB_EMPLOYER_MST.COMPANY_DESCRIPTION = txtCompanyDescription.Text;
                objIN_TB_EMPLOYER_MST.LOGIN_TILL = Convert.ToDateTime(txtlogintill.Text.ToString());
                objIN_TB_EMPLOYER_MST.DOWNLOAD_TILL = Convert.ToDateTime(txtdownloadtill.Text);
                objIN_TB_EMPLOYER_MST.MOBILE = txtmobile.Text;
                objIN_TB_EMPLOYER_MST.EMAIL = txtemail.Text;
                objIN_TB_EMPLOYER_MST.STATUS = 1;
                int EmployeerId = objclsEmployerDAL.SaveEmployerMst(objIN_TB_EMPLOYER_MST);
                //ClearAllControls();
                FillEmployer();
            }
            else
            {
                clsEmployerDAL objclsEmployeDAL = new clsEmployerDAL();
                IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
                objIN_TB_EMPLOYER_MST.ID = Convert.ToInt32(Session["EmployeId"].ToString());
                objIN_TB_EMPLOYER_MST.EMPLOYER_NAME = txtEmployeName.Text;
                objIN_TB_EMPLOYER_MST.COMPANY_DESCRIPTION = txtCompanyDescription.Text;
                objIN_TB_EMPLOYER_MST.DOWNLOAD_TILL = Convert.ToDateTime(txtdownloadtill.Text);
                objIN_TB_EMPLOYER_MST.LOGIN_TILL = Convert.ToDateTime(txtlogintill.Text);
                int EmployeId = objclsEmployeDAL.SaveEmployerMst(objIN_TB_EMPLOYER_MST);
                FillEmployer();
                //ClearAllControls();
                Session["EmployeId"] = null;
            }
        }

        catch (Exception)
        {
            throw;
        }




    }
    protected void FillEmployer()
    {
        try
        {
            List<IN_TB_EMPLOYER_MST> objIN_TB_EMPLOYER_MSTist = new List<IN_TB_EMPLOYER_MST>();
            clsEmployerDAL objclsEmployeDAL = new clsEmployerDAL();

            //objIN_TB_EMPLOYER_MSTist = objclsEmployeDAL.GetAllEmployerFullInfo();
            objIN_TB_EMPLOYER_MSTist = objclsEmployeDAL.GetAllEmployer();
            if (objIN_TB_EMPLOYER_MSTist != null)
            {
                grdEmploye.DataSource = objIN_TB_EMPLOYER_MSTist;
                grdEmploye.DataBind();
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
    protected void grdEmploye_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdEmploye.PageIndex = e.NewPageIndex;
        FillEmployer();
    }
    protected void grdEmploye_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Edt")
            {
                int EmployerId = Convert.ToInt32(e.CommandArgument.ToString());
                clsEmployerDAL objclsEmployerDAL = new clsEmployerDAL();
                IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();

                IN_TB_USER ObjIN_TB_USER = new IN_TB_USER();
                clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
                ObjIN_TB_USER = objclsUserLoginDAL.GetUserByEmployerID(EmployerId);
                if (ObjIN_TB_USER != null)
                {
                    txtEmployeName.Text = ObjIN_TB_USER.NAME;
                    txtemail.Text = ObjIN_TB_USER.EMAIL;
                    txtmobile.Text = ObjIN_TB_USER.MOBILE;
                    txtDob.Text = Convert.ToString(ObjIN_TB_USER.DOB);
                }

                objIN_TB_EMPLOYER_MST = objclsEmployerDAL.GetEmployerById(EmployerId);



                if (objIN_TB_EMPLOYER_MST != null)
                {

                    txtEmployeName.Text = objIN_TB_EMPLOYER_MST.EMPLOYER_NAME;
                    txtCompanyDescription.Text = objIN_TB_EMPLOYER_MST.COMPANY_DESCRIPTION;
                    DateTime dtill = (DateTime)objIN_TB_EMPLOYER_MST.DOWNLOAD_TILL;
                    txtdownloadtill.Text = dtill.ToString("dd-MMM-yyyy");
                    DateTime ltill = (DateTime)objIN_TB_EMPLOYER_MST.LOGIN_TILL;
                    txtlogintill.Text = ltill.ToString("dd-MMM-yyyy");
                    Session["EmployeId"] = EmployerId;


                }
            }

            if (e.CommandName == "Del")
            {
                int EmployerId = Convert.ToInt32(e.CommandArgument.ToString());
                clsEmployerDAL objclsEmployerDAL = new clsEmployerDAL();
                IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
                objclsEmployerDAL.DeleteEmploye(EmployerId);
                FillEmployer();
            }
        }
        catch (Exception)
        {

            throw;
        }
    }


}